import Vue from 'vue'
import Vuex from 'vuex'
import qs from 'qs'
Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        globalData: window.localStorage.getItem('globalData') ? qs.parse(window.localStorage.getItem('globalData')) : {},
    },
    mutations: {
        // 设置全局
        SET_GLOBAL(state, globalData) {
            window.localStorage.setItem('globalData', qs.stringify(globalData))
            state.globalData = globalData
        }
    },
    actions: {
        // 更新全局
        SET_GLOBAL({ commit }, globalData) {
            commit('SET_GLOBAL', globalData)
        },
    }
});

export default store